package com.antcloud.demo.antscheduler.handlers;

import com.alipay.antschedulerclient.common.SplitChunkDataResult;
import com.alipay.antschedulerclient.handler.IClusterJobSplitHandler;
import com.alipay.antschedulerclient.model.ClusterJobSplitContext;
import com.alipay.antschedulerclient.model.chunk.ShardingChunkData;

import java.util.ArrayList;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * @author manxing
 * @date 2018/9/2
 */
public class ClusterJobFirstSplitor implements IClusterJobSplitHandler<ShardingChunkData> {

    @Override
    public SplitChunkDataResult<ShardingChunkData> handle(ClusterJobSplitContext context) {
        SplitChunkDataResult<ShardingChunkData> splitChunkDataResult = new SplitChunkDataResult<>();
        ArrayList<ShardingChunkData> rangeChunkDatas = new ArrayList<>();
        for (int i = 0; i < 100; i++) {
            rangeChunkDatas.add(new ShardingChunkData(String.valueOf(i)));
        }
        splitChunkDataResult.setChunkDatum(rangeChunkDatas);
        splitChunkDataResult.setSuccess(true);
        return splitChunkDataResult;
    }

    @Override
    public String getName() {
        return "ANTSCHEDULER_CLUSTER_FIRST_SPLITOR";
    }

    @Override
    public ThreadPoolExecutor getThreadPool() {
        return null;
    }
}
